package com.database.mapper;


import com.database.character.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {

  //查询某级评论
  @Select("select * from comment where comment_type = #{commentType} and reply_id = #{postID}")
  List<Comment> getByCommentType(Integer postID , Integer commentType);

  @Select("select * from comment where comment_type = #{commentType} and reply_comment_id = #{replyId}")
  List<Comment> getByCommentTypeElse(Integer replyId, Integer commentType);

  //添加评论
  @Insert("insert into comment (reply_id, content, user_id, post_time, comment_type,reply_comment_id) " +
  "values (#{replyId},  #{content}, #{userId}, #{postTime}, #{commentType},#{replyCommentId})")
  int addComment(Comment comment);

  //删除评论
  @Delete("delete from comment where reply_id = #{replyArticleId}")
  int deleteCommentByArticleId(Integer replyArticleId);

  //根据id删除评论
  @Delete("delete from comment where comment_id = #{commentId}")
  int deleteCommentByCommentId(Integer commentId);

  @Select("select * from comment where comment_id = #{commentId}")
  Comment getCommentByCommentId(Integer commentId);

  @Update("update comment set content = #{content} , post_time = #{postTime} where comment_id = #{commentId}")
  int updateCommentByCommentId(Comment comment);


}
